package com.wangzhe.utils;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author 王哲
 * @ClassName PropertiesUtils
 * @create 2023--六月--上午11:15
 * @Description Properties读取工具类
 * @Version V1.0
 */
public class PropertiesUtils {

    private static Properties properties = new Properties();

    private static Map<String,String> properties_map = new ConcurrentHashMap<>();


    static {

        InputStream is = null;

        try {
            is = PropertiesUtils.class.getClassLoader().getResourceAsStream("application.properties");

            properties.load(new InputStreamReader(is,"UTF-8"));
            properties.keySet().forEach(key->{
                properties_map.put((String) key, (String) properties.get(key));
            });
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if (is!=null){
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    public static String getString(String key){
        return properties_map.get(key);
    }

//    public static void main(String[] args) {
//        String string = getString("db.driver.name");
//        System.out.println("string = " + string);
//    }

}
